package com.cy.store.controller;

import com.cy.store.entity.Product;
import com.cy.store.service.IProductService;
import com.cy.store.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("products")
public class ProductController extends BaseController{

    @Autowired
    IProductService productService;

    /**
     * 展示热销商品
     */
    @RequestMapping("host_list")
    JsonResult<List<Product>> hostList(){
        List<Product> list = productService.findHotList();
        return new JsonResult<List<Product>>(OK, list);
    }

    /**
     * 展示商品详细信息
     */
    @GetMapping("{id}/details")     // ?
    JsonResult<Product> details(@PathVariable("id") Integer id){
        Product product = productService.findById(id);
        return new JsonResult<Product>(OK, product);
    }
}
